package com.cloud.hystrix.controller;

import com.cloud.domain.TOrder;
import com.cloud.hystrix.service.IHystrixTOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/6/25 14:26
 * @Desc
 * @Remarks
 */
@RequestMapping("/hystrix")
@RestController
public class HystrixController {
    @Autowired
    private IHystrixTOrderService iTOrderService;

    @RequestMapping("/getById")
    public TOrder getById(@RequestParam("id") Long id) {
        if (null == id) {
            return null;
        }
//        wait(3);
        return iTOrderService.getById(id);
    }

    @RequestMapping("/circuitBreaker")
    public String circuitBreaker(@RequestParam("id") Long id) {
        if (null == id) {
            return null;
        }
        return iTOrderService.findCircuitBreaker(id);
    }


    @RequestMapping("/listAll")
    public List<TOrder> listAll() {
        return iTOrderService.list();
    }
}
